import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';

/**
 * Generated class for the MyproductPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-myproduct',
  templateUrl: 'myproduct.html',
})
export class MyproductPage {
  myproduct:any;
  type:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,public busi:BusiProvider,public native:NativeProvider) {
    this.getMyproduct();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad MyproductPage');
  }
  getMyproduct(){
    this.busi.getMyProduct().subscribe(
      data=>{
        this.myproduct = data.myproduct;
      },
      error=>{

      }
    );
  }

  productdetail(prodid){
    this.navCtrl.push("ProductdetailPage",{prodid:prodid});
  }

  sxjPro(type){
    let body = {
      prods:this.myproduct,
      type:type
    }
    this.busi.sxjPro(body).subscribe(
      data=>{
        if(type == '1')
        this.native.showToast("商品上架成功！");
        else
        this.native.showToast("商品下架成功！");
        this.getMyproduct();
      },error=>{}
    )
  }

}
